<template>
  <div class="">
    <ProTable
        :tableSource="tableData"
        :columns="columns"
        @onload="getList"
        :shouldEdit="false"
        :initParam="{}"
    >

      <template #bodyCell="{record,column}">
        <template v-if="column.dataIndex === 'operation'">
          <ProButton type="link" :options="['view']" :cancel="tabke_item_cancel" :finished="(status)=>table_item_finished(status,record)"></ProButton>
        </template>
        <template v-else>
          {{ record[column.dataIndex] }}
        </template>
      </template>
    </ProTable>
  </div>
</template>

<script setup lang="ts">
import fetchApi from "@/api/system/operlog";
import { buttonType } from "@/components/ProButton/interface";
import type { TableProps } from "@/components/ProTable";
import ProTable from "@/components/ProTable";
import { has } from "lodash";
import { getCurrentInstance, ref } from "vue";

const { proxy }:any = getCurrentInstance();

const tableData = ref<TableProps['tableSource']>({
  current:1,
  pageSize:20,
  total:0,
  list:[]
})

const columns:TableProps['columns'] = [
  {
    title:"操作用户",
    dataIndex:"s_create_by",
    search:true,
    hidden:true
  },
  {
    title:"操作时间",
    dataIndex:"s_begin_date",
    search:true,
    searchType:'rangeDate',
    hidden:true
  },
  {
    title:"操作结果",
    dataIndex:"s_succeed",
    search:true,
    searchType:'select',
    hidden:true,
    enum:[{label:"成功",value:1},{label:"失败",value:0}]
  },
  {
    title:"操作用户",
    dataIndex:"user",
  },
  {
    title:"操作时间",
    dataIndex:"create_time",
  },
  {
    title:"操作模块",
    dataIndex:"title",
  },
  {
    title:"操作说明",
    dataIndex:"remark",
  },
  {
    title:"请求方式",
    dataIndex:"type",
  },
  {
    title:"请求路径",
    dataIndex:"path",
  },
  {
    width:80,
    dataIndex:"operation",
    title:"操作"
  }
]

const getList = async (params:any)=>{
  let other:any = {}
  if(has(params,'s_begin_date')){
    other.s_begin_date = params.s_begin_date[0]
    other.s_end_date = params.s_begin_date[1]
  }
  const res = await fetchApi.systemOperation({...params,...other})
  if(res.code === 200 && tableData.value){
    tableData.value.list = res.data.list
    tableData.value.total = res.data.total
    tableData.value.current = params.page
    tableData.value.pageSize = params.limit
  }
}

// 表格行按钮点击事件
const table_item_finished = async (status:buttonType,item:any)=>{
  if(status === 'delete'){
    return await table_delete(item)
  }
  return Promise.resolve()
}


// const getDisableValue = (list:any,value:any)=>{
//   const item = chain(list).find(['value',value]).value()
//   if(item && item.locale){
//     return item.locale[locale.value as "en" | "ch"]
//   }
//   return item && item.label ? item.label : '-'
// }

// 删除
const table_delete = async (item:any)=>{
  const res = await fetchApi.DeletedMenu({id:item.id})
  proxy.$format.response(res)
  // await getList()
}

const tabke_item_cancel = ()=>{
  alert("取消")
}



</script>

<style scoped lang="less">

</style>
